

package com.example.text.service;
import com.example.text.entity.Result;
import com.example.text.entity.User;
import com.example.text.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;


@Service
public  class UserService implements UserMapper {



    private UserMapper userMapper;
    @Autowired
    public UserService(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    @Override
    public List<User> findALL() {
        return userMapper.findALL();
    }

    @Override
    public List<User> findById(String id) {
        id="%"+ id +"%";
        return userMapper.findById(id);
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int deleteById(Integer id) {
        return userMapper.deleteById(id);

    }
    @Override
    public User findOne(User user){
        return userMapper.findOne(user );
    }

    public Result login(User user) {
        String id=user.getId();
        String password=user.getPassword();
        User one=findOne(user);
        if(id.equals("")||password.equals("")){
            return Result.error("404","请输入用户名或密码");
        } else if (one == null){
            return Result.error("110","用户名或密码错误");

        } else
            return Result.success(one);
    }
}
